package com.zero.qth.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zero.common.core.domain.page.PageDomain;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zero.common.annotation.log.Log;
import com.zero.common.core.basecontroller.BaseController;
import com.zero.common.core.domain.result.AjaxResult;
import com.zero.common.core.enums.BusinessType;
import com.zero.qth.domain.Orders;
import com.zero.qth.service.IOrdersService;
import com.zero.common.core.utils.poi.ExcelUtil;
import com.zero.common.core.domain.page.TableDataInfo;

/**
 * 订单列表Controller
 * 
 * @author cai-xu-kun
 * @date 2025-08-08
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "订单列表")
@RequestMapping("/qth/orders")
public class OrdersController extends BaseController {

    private final IOrdersService ordersService;

    /**
     * 查询订单列表分页
     */
    @ApiOperation("查询订单列表分页")
    @PreAuthorize("@ss.hasPermi('qth:orders:list')")
    @GetMapping("/list")
    public TableDataInfo list(Orders orders) {
        PageDomain pageDomain = this.startPage();
        Page<Orders> p = new Page<>(pageDomain.getPageNum(), pageDomain.getPageSize());
        Page<Orders> page = ordersService.selectOrdersListPage(orders, p);
        return this.getDataTable(page);
    }

    /**
     * 导出订单列表列表
     */
    @ApiOperation("导出订单列表列表")
    @PreAuthorize("@ss.hasPermi('qth:orders:export')")
    @Log(title = "订单列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Orders orders) {
        List<Orders> list = ordersService.selectOrdersList(orders);
        ExcelUtil<Orders> util = new ExcelUtil<Orders>(Orders.class);
        util.exportExcel(response, list, "订单列表数据");
    }

    /**
     * 获取订单列表详细信息
     */
    @ApiOperation("获取订单列表详细信息")
    @PreAuthorize("@ss.hasPermi('qth:orders:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(ordersService.selectOrdersById(id));
    }

    /**
     * 新增订单列表
     */
    @ApiOperation("新增订单列表")
    @PreAuthorize("@ss.hasPermi('qth:orders:add')")
    @Log(title = "订单列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Orders orders) {
        return toAjax(ordersService.insertOrders(orders));
    }

    /**
     * 修改订单列表
     */
    @ApiOperation("修改订单列表")
    @PreAuthorize("@ss.hasPermi('qth:orders:edit')")
    @Log(title = "订单列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Orders orders) {
        return toAjax(ordersService.updateOrders(orders));
    }

    /**
     * 删除订单列表
     */
    @ApiOperation("删除订单列表")
    @PreAuthorize("@ss.hasPermi('qth:orders:remove')")
    @Log(title = "订单列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(ordersService.deleteOrdersByIds(ids));
    }
}
